//整合三个文件
import { createStore } from 'vuex';
import mutations from './mutations';
import actions from './actions';
import state from './state';

export default createStore(
    {
        state,
        mutations,
        actions,
        //筛选数据
        getters: {
            // 提供一个getters来获取当前选中的古诗名，匹配
            selectedPoemData: state => {
                if (state.selectedPoem) {
                    // return state.poems.find(poem => poem.title === state.selectedPoem);
                    return state.poems.find(poem => poem.title .includes(state.selectedPoem));
                }
                return null;
            },
            
            //选地区介绍
            selectedRegionData: (state) => {
                // 从地区数据中找到选中地区的介绍
                return state.regions.find((region) => region.name === state.selectedRegion);
            },
           selectedEmotionData: (state) => {
               return state.emotionsData[state.selectedProvince] || {};
           },
           selectedcityData: (state) => {
               return state.cityData[state.selectedProvince] || {};
           }
        }
    }
    

)